#{extends 'main.html' /}
#{set title:'Edit an Item' /}
<html>

<script type="text/javascript">

function change() {
	
	document.getElementById("viewItemDetails").value = "false";
	document.forms["myform"].submit();
	
	
}

</script>

</head>
<body>

<h3> Edit an Item </h3> <br />


 
<form id ="myform" action="@{Items.editItem()}" method="POST">
    Select an item to edit  <select size="1" name="itemID" > 
            #{list items:items, as:'Item'}
                #{if i!=null && Item.id == i.id }
                <option value="${Item.id}" selected = "selected">${Item.name}</option>
                #{/if}
                #{else}
                <option value="${Item.id}">${Item.name}</option>
                #{/else}
            #{/list}
            </select>
      <input type="hidden" id = "viewItemDetails" name = "viewItemDetails" value = true>
    	<br /> <br />
    #{if i!=null}	
    Name <input type="text" id = "name" name="name" value = "${i.name}"  "/> <br /> <br />
    Content <textarea id = "content" name="content" rows=3 cols=20 > ${i.content}</textarea> <br /> <br />
    time <input type="text" id = "time" name="dateAndTime" value = "${new java.text.SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(i.dateAndTime)}" /> <br /> <br />
    Assign User (By Username): <input type="text" id = "assigneeUsername" name="assigneeUsername"  /> 
	(This is optional, if you don't want to assign users now, leave it empty)   <br>  
   	<input type="submit" value="Submit" name = "Submit" /> <br /> <br /> <br />
   	
   #{/if}
   
   #{else}
   
   	<p style="color:red">
        "Wrong Item ID"
	</p>
   
   #{/else}
    
</form>


<button type = "button" onclick = "change()"> View Item Details </button>  <br /> <br />

<p style="color:blue">
        ${result_item}
</p>

#{if flash.error}
    <p style="color:red">
        ${flash.error}
    </p>
#{/if}

<form action="@{Items.addTag()}" method="POST">
Item <select size="1" name="itemID"> 
            #{list items:items, as:'Item'}
                <option value="${Item.id}">${Item.name}</option>
            #{/list}
            </select>

Add Tag <select size="1" name="tagID"> 
            #{list items:tags, as:'Tag'}
                <option value="${Tag.id}">${Tag.name}</option>
            #{/list}
            </select>
<input type = "submit" value = "Submit" name = "Submit"/>            
</form>

<p style="color:blue">
        ${result2}
</p>

<form action="@{Items.removeTag()}" method="POST">
Item <select size="1" name="itemID"> 
            #{list items:items, as:'Item'}
                <option value="${Item.id}">${Item.name}</option>
            #{/list}
            </select>

Remove Tag <select size="1" name="tagID"> 
            #{list items:tags, as:'Tag'}
                <option value="${Tag.id}">${Tag.name}</option>
            #{/list}
            </select>
<input type = "submit" value = "Submit" name = "Submit"/>            
</form>

<p style="color:blue">
        ${result5}
</p>


<form action="@{Items.relateToEntity()}" method="POST">
Item <select size="1" name="itemID"> 
            #{list items:items, as:'Item'}
                <option value="${Item.id}">${Item.name}</option>
            #{/list}
            </select>

Set Entity <select size="1" name="entityID"> 
            #{list items:entities, as:'Eentity'}
                <option value="${Eentity.id}">${Eentity.name}</option>
            #{/list}
            </select>
<input type = "submit" value = "Submit" name = "Submit"/>            
</form>

<p style="color:blue">
        ${result3}
</p>


<form action="@{Items.relateToTopic()}" method="POST">
Item <select size="1" name="itemID"> 
            #{list items:items, as:'Item'}
                <option value="${Item.id}">${Item.name}</option>
            #{/list}
            </select>

Set Topic <select size="1" name="topicID"> 
            #{list items:topics, as:'Topic'}
                <option value="${Topic.id}">${Topic.title}</option>
            #{/list}
            </select>
<input type = "submit" value = "Submit" name = "Submit"/>            
</form>

<p style="color:blue">
        ${result4}
</p>

 

</html>